package com.bravo.user.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.bravo.user.entity.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * user数据访问接口
 * @author Yuyong
 *
 */
public interface UserRepository extends JpaRepository<User,String>, JpaSpecificationExecutor<User> {

    /**
     * 更新关注数
     * @param userId
     * @param x
     */
    @Modifying
    @Transactional
    @Query(value = "update tb_user u set u.follow_count = u.follow_count + ?2 where u.id = ?1",nativeQuery = true)
    void incFollowCount(String userId,int x);

    /**
     * 更新粉丝数
     * @param userId 用户ID
     * @param x 粉丝数
     */
    @Transactional
    @Modifying
    @Query(value = "update tb_user u set u.fans_count = u.fans_count + ?2 where u.id = ?1", nativeQuery = true)
    void incFanscount(String userId,int x);

    /**
     * 根据手机号查询用户
     * @param mobile
     * @return
     */
    User findByMobile(String mobile);
}
